// Copyright (c) 2025 Huawei Technologies Co., Ltd.
// openUBMC is licensed under Mulan PSL v2.
// You can use this software according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of Mulan PSL v2 at:
//         http://license.coscl.org.cn/MulanPSL2
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
// See the Mulan PSL v2 for more details.
//
// Description: 封装和解析VMM消息报文

#ifndef VMM_MESSAGE_HPP
#define VMM_MESSAGE_HPP

#include <cstdint>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <stdexcept>
#include "Defines.hpp"

class VMMMessage {
private:
    uint8_t opcode_{0};                 ///< 操作码，1字节
    uint8_t status_{0};                 ///< 状态码，1字节
    uint8_t sack_{0};                   ///< 失败原因，1字节
    uint8_t seq_{0};                    ///< 序列号，1字节
    uint32_t length_{0};                ///< 数据长度，4字节（big-endian）
    std::vector<uint8_t> data_;         ///< 数据内容

public:
    VMMMessage();
    ~VMMMessage();

    std::vector<uint8_t> Pack(uint8_t opCode, const std::vector<uint8_t>& data,
        uint8_t status, uint8_t sack, uint8_t seq);
    std::vector<uint8_t> SffDataPack(uint8_t dataType, uint8_t state, uint32_t dataLength, uint8_t seq);
    bool Unpack(const std::string& data);

    uint8_t GetOpCode() const;
    uint8_t GetStatus() const;
    uint8_t GetSack() const;
    uint8_t GetSeq() const;
    uint32_t GetLength() const;
    std::vector<uint8_t> GetData() const;
};

#endif // VMM_MESSAGE_HPP